//
//  link_list_flip.hpp
//  cpp_algorithm
//
//  Created by 李贺 on 2021/11/26.
//

#ifndef link_list_flip_hpp
#define link_list_flip_hpp

#include <stdio.h>
#include <vector>
#include <iostream>
using namespace std;

class ListflipNode {
        
public:
    int val;
    ListflipNode *next;
    ListflipNode(int x): val(x),next(NULL){}
};

class Solution_list_flip {
    

public:
    
    
    ListflipNode *flipLinkList(ListflipNode *head) {
        if (NULL == head) {
            return NULL;
        }
        
        ListflipNode *cur = head;
        ListflipNode *temp;
        ListflipNode *pre = nullptr;
        
        while (cur) {
            temp = cur->next;
            cur->next = pre;
            pre = cur;
            cur = temp;
        }
        return pre;
    }
    
    void printLinklist(ListflipNode *head) {
        if (NULL == head) {
            return ;
        }

        ListflipNode *current_cousor = head;
        while (current_cousor != NULL) {
            cout << current_cousor->val << "\n";
            current_cousor = current_cousor->next;
        }
    }
    
    void test() {
        ListflipNode *node1 = new ListflipNode(1);
        ListflipNode *node2 = new ListflipNode(2);
        ListflipNode *node3 = new ListflipNode(3);
        ListflipNode *node4 = new ListflipNode(4);
        node1->next = node2;
        node2->next = node3;
        node3->next = node4;
        node4->next = NULL;
        
        ListflipNode *res = flipLinkList(node1);
        printLinklist(res);
    }
};

#endif /* link_list_flip_hpp */
